package servlet.order;

import util.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/updateorders.do")
public class UpdateOrderMsgServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect("GotoOrderServlet");
        int id = Integer.parseInt(req.getParameter("id"));
        String address = req.getParameter("address");
        String address_name = req.getParameter("address_name");
        String phone = req.getParameter("phone");
        DbUtil db = new DbUtil();
        String sql = "update orders set address = '"+address+"', address_name='"+address_name+"', phone = '"+phone+"' where id = '"+id+"'";
        System.out.println(sql);
        if (db.executeUpdate(sql)<0){
            resp.sendRedirect("GotoOrderServlet");
        }else {
            resp.sendRedirect("GotoOrderServlet");
        }
//        db.executeUpdate(sql);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
